﻿using System;
using System.ComponentModel.DataAnnotations;

namespace OurWedding1.Models
{
    [MetadataType(typeof(TaskBuddy))]
    public partial class Task
    {
        public int DaysLeft()
        {
            var now = DateTime.Now;
            if (!Deadline.HasValue)
            {
                return -1;
            }
            var deadline = Deadline.Value;
            var span = deadline - now;
            return span.Days;
        }
    }

    public class TaskBuddy
    {
        public int TaskId { get; set; }
        [Required(ErrorMessageResourceType = typeof (Resources), ErrorMessageResourceName = "Task_Name_Required")]
        [Display(ResourceType = typeof (Resources), Name = "Task_Name")]
        public string Name { get; set; }

        [Display(ResourceType = typeof (Resources), Name = "Task_Deadline")]
        [DataType(DataType.Date)]
        public DateTime? Deadline { get; set; }

        [Display(ResourceType = typeof (Resources), Name = "Task_GuestId")]
        public int? GuestId { get; set; }

        [Required(ErrorMessageResourceType = typeof (Resources), ErrorMessageResourceName = "Task_ExpenseId_Required")]
        [Display(ResourceType = typeof (Resources), Name = "Task_ExpenseId")]
        public int ExpenseId { get; set; }

        [Required(ErrorMessageResourceType = typeof (Resources), ErrorMessageResourceName = "Task_isDone_Required")]
        [Display(ResourceType = typeof (Resources), Name = "Task_isDone")]
// ReSharper disable InconsistentNaming
        public bool isDone { get; set; }
// ReSharper restore InconsistentNaming

        [Display(ResourceType = typeof (Resources), Name = "Task_ExpenseId")]
        public virtual Expense Expens { get; set; }

        [Display(ResourceType = typeof (Resources), Name = "Task_GuestId")]
        public virtual Guest Guest { get; set; }
    }

}